@include('admin.public.head')

<style type="text/css">

    .inner_btn {
        background: #19a97b;
        color: white;
        padding: 5px 8px;
        border-radius: 2px;
    }

    .control-label div{
        position: absolute;
        left: 30%;
        text-align: right;
    }

</style>


<div class="ibox-title">
    <h5>规则设置</h5>
</div>
<div class="ibox-content">

    <form method="get" class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                請假規則：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <script id="leave" name="leave" type="text/plain" style="height:300px;">{!! $leave??'' !!}</script>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                兌換積分过期时间：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <input  name="expire_duration" class="form-control" id="start_time" type="text/plain" value="{{$expire_duration}}" ></br>
                    <a onclick="points_cleared($(this))" class="btn btn-primary" type="submit">積分清零操作</a>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                補堂規則：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <script id="make_up" name="make_up" type="text/plain" style="height:300px;">{!! $make_up??'' !!}</script>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                自選課相關規則：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <script id="optional_course" name="optional_course" type="text/plain" style="height:300px;">{!! $optional_course??'' !!}</script>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                积分規則：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <script id="integral_rul" name="integral_rul" type="text/plain" style="height:300px;">{!! $integral_rul??'' !!}</script>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                用户服务条款：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <script id="user_service_rul" name="user_service_rul" type="text/plain" style="height:300px;">{!! $user_service_rul??'' !!}</script>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                現金券優惠券條款：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <script id="cash_coupon_rul" name="cash_coupon_rul" type="text/plain" style="height:300px;">{!! $cash_coupon_rul??'' !!}</script>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                积分方案图片：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <input type="file" name="image" class="form-control"  value="">
                    <img src="{{$system_images??''}}" width="300" height="150">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                公司收款码：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <input type="file" name="image_2" class="form-control"  value="">
                    <img src="{{$company_payment_code??''}}" width="300" height="150">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                现金卷图片：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <input type="file" name="image_4" class="form-control"  value="">
                    <img src="{{$cash_picture??''}}" width="300" height="150">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                禮品兌換圖片列表：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <input type="file" name="image_3" class="form-control"  value="">
                    <img src="{{$goods_integral_cove??''}}" width="300" height="150">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">
                <div>
                    <a onclick="integral_do($(this))" class="btn btn-primary" type="submit">保存</a>
                </div>
                商品兑换条款：
            </label>
            <div class="col-sm-6">
                <div class="recharge_agreement">
                    <script id="goods_rul" name="goods_rul" type="text/plain" style="height:300px;">{!! $goods_rul??'' !!}</script>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

    </form>

</div>

@include('admin.public.laydate')

<script>

    var leave_content = UE.getEditor('leave');
    var make_up_content = UE.getEditor('make_up');
    var optional_course_content = UE.getEditor('optional_course');
    var integral_rul_content = UE.getEditor('integral_rul');
    var user_service_rul_content = UE.getEditor('user_service_rul');
    var cash_coupon_rul_content = UE.getEditor('cash_coupon_rul');
    var goods_rul_content = UE.getEditor('goods_rul');


    function integral_do(){

        var form = new FormData();

        var leave = leave_content.getContent();
        var goods_rul = goods_rul_content.getContent();
        var make_up = make_up_content.getContent();
        var moptional_course =optional_course_content.getContent();
        var integral_rul = integral_rul_content.getContent();
        var user_service_rul = user_service_rul_content.getContent();
        var cash_coupon_rul = cash_coupon_rul_content.getContent();
        var image = $('input[name="image"]')[0].files[0];
        var image_2 = $('input[name="image_2"]')[0].files[0];
        var image_3 = $('input[name="image_3"]')[0].files[0];
        var image_4 = $('input[name="image_4"]')[0].files[0];
        var expire_duration = $('input[name="expire_duration"]').val();

        form.append("leave", leave);
        form.append("make_up", make_up);
        form.append("goods_rul", goods_rul);
        form.append("optional_course", moptional_course);
        form.append("expire_duration", expire_duration);
        form.append("integral_rul", integral_rul);
        form.append("user_service_rul", user_service_rul);
        form.append("cash_coupon_rul", cash_coupon_rul);
        form.append("image", image);
        form.append("image_2", image_2);
        form.append("image_3", image_3);
        form.append("image_4", image_4);

        $.ajax({
            type: 'POST',
            url: '/rule_edit' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });
    }

</script>

<script>
    function points_cleared() {
        //var url = obj.attr('url');
        var title =  "你確定要清零全部用戶的兌換積分? 請注意檢查是否已過期，并且妥善處理";
        var botton =  "清零";
        var result =  "清零成功";

        swal({
            title: title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: botton,
            closeOnConfirm: false
        }, function () {

            $.ajax({
                type: "post",
                url: "/rule_pints_cleared",
                dataType: "json",
                success: function(data) {

                    var swal_json = {
                        title : result,
                        type : "success"
                    }

                    swal(swal_json,function(isConfirm){
                        layer.close(isConfirm);
                    });

                }
            });

        });

    }
</script>
